﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LRSystem
{
    public static class PacketClassDictionary
    {
        private static Dictionary<UInt16, Type> pkdic = new Dictionary<UInt16, Type>();
        static PacketClassDictionary()
        {
            AddPacketClass(MagneticReport.type, typeof(MagneticReport));
        }

        public static void AddPacketClass(UInt16 tp, Type classtp)
        {
            if (pkdic.ContainsKey(tp) == false)
                pkdic.Add(tp, classtp);
        }

        public static object CreateInstanse(UInt16 tp)   // 根据类型创建类实例
        {
            if (pkdic.ContainsKey(tp))
                return Activator.CreateInstance(pkdic[tp]);
            else
                return null;
        }

        public static void RemovePacketClass(UInt16 tp)  // 根据类型从字典中删除相应类
        {
            pkdic.Remove(tp);
        }
    }
}
